package day07;
/**
 *
 * @since 09:40
 * @author wuguidong@cskaoyan.onaliyun.com
 */

/**
 * 问题1: 思考注释一下面的代码能否放开?会不会报错?为了更好的代码可读性,可以怎么做?
 * 问题2: 思考控制台输出的顺序,提供必要的文字说明解释代码为何如此执行。
 * 问题3: Homework building和Homework constructor会不会输出,为什么?
 *
 * 类加载:
 * 加载 --> 连接 --> 初始化
 */
public class DebugDemo {
    static Student s = new Student();
    static {
        // 静态代码块中的局部位置
        System.out.println("DebugDemo类的静态代码块");
    }

    {
        // 局部位置
        System.out.println("Homework building");
        s = null;
    }

    public static void main(String[] args) {
        System.out.println("main");
        // 注释一
        System.out.println(DebugDemo.s.age);
        Person p = new Person("刘备");
        System.out.println(p.name);
    }

    public DebugDemo() {
        System.out.println("Homework constructor");
    }
}

class Person {
    {
        name = "赵云";
        System.out.println("Person building");
    }

    String name = "曹操";
    static Student s = new Student();

    public Person() {
    }

    public Person(String name) {
        System.out.println("Person constructor");
        this.name = name;
    }
}

class Student {
    int age = 10;

    {
        System.out.println("Student building");
        age = 20;
    }

    public Student(int age) {
        this.age = age;
    }

    public Student() {
        System.out.println("Student constructor");
    }
}